package demo.practice.dp;

public class P55 {


    public boolean canJump(int[] nums) {
        // [2,3,1,1,4]
        //能跳到

        boolean[] dp = new boolean[nums.length];

        dp[0] = true;
        for (int i = 0; i < nums.length; i++) {
            if (!dp[i]) {
                return false;
            }

            if (i + nums[i] >= nums.length) {
                return true;
            }
            if (i + nums[i] >= nums.length && dp[i + nums[i]]) {
                continue;
            }

            for (int j = i + 1; j <= i + nums[i]; j++) {
                dp[j] = true;
            }
        }
        return dp[nums.length - 1];
    }
}
